<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE>
<html>
<head>
<title>任务任务详情</title>
</head>
<body>
	<div class="col-lg-12">
		<div id="message"></div>
		<div class="panel panel-default bk-bg-white">
			<div class="panel-heading bk-bg-white">
				<h2>
					任务状态 <span style="font-size: 14px; padding-left: 10px"> <c:if
							test="${task.taskStatus eq '1' }">
							<span class="label label-default">保存未发布</span>
							<span class="label label-info" id="cancelOrder">撤销未接单任务</span>
						</c:if> <c:if test="${task.taskStatus eq '2' }">
							<span class="label label-info">已发布</span>
							<span class="label label-info" id="cancelOrder">撤销未接单任务</span>
						</c:if> <c:if test="${task.taskStatus eq '3' }">
							<span class="label label-warning">已撤销</span>
						</c:if> <c:if test="${task.taskStatus eq '4' }">
							<span class="label label-success">进行中</span>
							<span class="label label-info" id="cancelOrder">撤销未接单任务</span>
						</c:if> <c:if test="${task.taskStatus eq '5' }">
							<span class="label label-success">已完成</span>
						</c:if>
					</span>
				</h2>
			</div>
			<div class="panel-body">
				<div class="form-group col-sm-12">
					<div class="col-sm-12">
						<div class="table-responsive">
							<table class="table table-bordered">
								<thead>
									<tr>
										<th>任务总订单数</th>
										<th>未接单</th>
										<th>待买手操作</th>
										<th>待确认金额并发货</th>
										<th>待买手评价</th>
										<th>待确认评价</th>
										<th>已完成</th>
										<th>已撤销</th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td>${orderCount.all }</td>
										<td>${empty orderCount.order1?0:orderCount.order1  }</td>
										<td>${empty orderCount.order2?0:orderCount.order2 }</td>
										<td>${empty orderCount.order3?0:orderCount.order3 }</td>
										<td>${empty orderCount.order4?0:orderCount.order4 }</td>
										<td>${empty orderCount.order5?0:orderCount.order5  }</td>
										<td>${empty orderCount.order7?0:orderCount.order7  }</td>
										<td>${empty orderCount.order8?0:orderCount.order8  }</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
					<div style="text-align: center;">
						<span class="label label-warning" id="orderlist">查看所有接此任务的买手及其订单信息</span>
					</div>
				</div>
			</div>
		</div>

		<div class="panel panel-default bk-bg-white">
			<div class="panel-heading bk-bg-white">
				<h2>
					任务详情<small>(商家生财ID：<span style="color: #FFB253;">${task.businessUserId }</span>)
					</small>
				</h2>
			</div>
			<div class="panel-body">
				<div class="form-group col-sm-12">
					<div class="col-sm-12">
						<div class="table-responsive">
							<table class="table table-bordered">
								<thead>
									<tr>
										<th style="width: 70%;">任务商品信息</th>
										<th>成交价（元）</th>
										<!-- <th>每单拍下数量</th> -->
									</tr>
								</thead>
								<tbody>
									<tr>
										<td>
											<!-- <div style="float: left;"><img width="100" height="100" src="https://gd1.alicdn.com/imgextra/i5/TB13XNyLFXXXXbsXVXXYXGcGpXX_M2.SS2_400x400.jpg"/></div> -->
											<div style="float: left;">
												<img width="100" height="100"
													src="${pic_root }${productin.id.mainMap }" />
											</div>
											<div style="float: left; width: 70%; padding-left: 15px;">
												<p>${productin.id.productName }</p>
												<p>
													<c:if
														test="${productin.id.productLink !='N' and !empty productin.id.productLink}">
														<a target="_blank" href="${productin.id.productLink }">商品链接</a>
													</c:if>
												</p>
											</div>
										</td>
										<td>￥${productin.id.price }</td>
										<%-- <td>${productin.id.perOrderContainingNum }</td> --%>
									</tr>
								</tbody>
							</table>
						</div>

						<form class="form-horizontal">
							<div class="row">
								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">平台：</label>
									<div class="col-sm-7" style="padding-top: 10px;">
										${task.platform.platformName}</div>
								</div>

								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">端口：</label>
									<div class="col-sm-7" style="padding-top: 10px;">${task.terminal.terminalName}</div>
								</div>

								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">任务类型：</label>
									<div class="col-sm-7" style="padding-top: 10px;">${task.taskGroupTypeId.taskTypeName}</div>
								</div>
							</div>
							<div class="row">
								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">价格区间：</label>
									<div class="col-sm-7" style="padding-top: 10px;">${productin.id.lowestPrice }
										- ${productin.id.highestPrice }</div>
								</div>
								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">商品所在地：</label>
									<div class="col-sm-7" style="padding-top: 10px;">${productin_area }</div>
								</div>
								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">包邮：</label>
									<div class="col-sm-7" style="padding-top: 10px;">${basecommission.freeShippingMark==0?'包邮':'不包邮'}</div>
								</div>
							</div>
							<div class="row">
								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">直通车：</label>
									<div class="col-sm-7" style="padding-top: 10px;">${task.directTrain==1?'是':'否'}</div>
								</div>

								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">排序方式：</label>
									<div class="col-sm-7" style="padding-top: 10px;">
										<c:choose>
											<c:when test="${task.searchKeywordSortWay==1 }">
											按销量优先(推荐，排序较稳定)
										</c:when>
											<c:otherwise>
											按综合排序
										</c:otherwise>
										</c:choose>
									</div>
								</div>

								<div class="form-group col-sm-4">
									<label class="col-sm-5 control-label">收货/付款人数：</label>
									<div class="col-sm-7" style="padding-top: 10px;">${task.peopleNumber }</div>
								</div>
							</div>

							<div class="row">
								<label class="col-sm-2 control-label">订单留言：</label>
								<div class="col-sm-10" style="padding-top: 10px;">${task.unifiedOrderMessage }</div>
							</div>

							<div class="row">
								<label class="col-sm-2 control-label">提醒买手注意事项：</label>
								<div class="col-sm-10" style="padding-top: 10px;">${task.tipBuyersNotes }</div>
							</div>

							<div class="form-group col-sm-12">
								<label class="col-sm-2 control-label">关键词：</label>
								<div class="col-sm-10">
									<div class="table-responsive">
										<table class="table table-bordered">
											<thead>
												<tr>
													<c:forEach items="${searchKeywords }" var="searchKeyword">
														<th>${searchKeyword.searchkeyword }</th>
													</c:forEach>
												</tr>
											</thead>
											<%-- <tbody>
												<tr>
													<c:forEach items="${searchKeywords }" var="searchKeyword">
														<th>${searchKeyword.releaseorders }</th>
													</c:forEach>
												</tr>
											</tbody> --%>
										</table>
									</div>
								</div>
							</div>

							<div class="form-group col-sm-12">
								<label class="col-sm-2 control-label">放单时间：</label>
								<div class="col-sm-10">
									<div class="table-responsive">
										<table class="table table-bordered">
											<thead>
												<tr>
													<th>放单时间</th>
													<th>间隔</th>
													<th>放单数</th>
													<th>频率</th>
												</tr>
											</thead>
											<tbody>
												<c:forEach items="${releaseOrders }" var="releaseOrder">
													<tr>
														<td><fmt:formatDate
																value="${releaseOrder.periodStartTime }"
																pattern="yyyy-MM-dd HH:mm:ss" />~<fmt:formatDate
																value="${releaseOrder.periodEndTime }"
																pattern="yyyy-MM-dd HH:mm:ss" /></td>
														<td>60分钟</td>
														<td>${releaseOrder.releaseOrders }</td>
														<td>平均每6分钟放出一单</td>
													</tr>
												</c:forEach>
												<c:if test="${empty releaseOrders}">
													<tr>
														<td><fmt:formatDate
																value="${task.taskPublishedTime }"
																pattern="yyyy-MM-dd HH:mm:ss" />
														<td>0分钟</td>
														<td>6</td>
														<td>0分/次</td>
													</tr>
												</c:if>
											</tbody>
										</table>
									</div>
								</div>
							</div>
							<c:if test="${taskActions.size()>0 }">
								<div class="form-group col-sm-12">
									<label class="col-sm-2 control-label">任务操作示意图：</label>
									<div class="col-sm-12">
										<c:forEach items="${taskActions }" var="taskAction">
											<img class="col-sm-2"
												src="${pic_root }${taskAction.id.exampleFig}">
										</c:forEach>
										<!-- <img class="col-sm-2" src="https://img.alicdn.com/imgextra/i4/651051720/TB2xzaekXXXXXcdXXXXXXXXXXXX_!!651051720.jpg">
									<img class="col-sm-2" src="https://img.alicdn.com/imgextra/i4/651051720/TB2xzaekXXXXXcdXXXXXXXXXXXX_!!651051720.jpg"> -->
									</div>
								</div>
							</c:if>

							<c:if test="${productin_not.size()>0 }">
								<div class="form-group col-sm-12 form-horizontal">
									<div class="row">
										<label class="col-sm-2 control-label">附属商品：</label>
									</div>
									<div class="row">
										<c:forEach items="${productin_not }" var="productin1">
											<div class="col-sm-6">
												<div class="table-responsive">
													<table class="table table-bordered">
														<thead>
															<tr>
																<th>任务商品</th>
																<th>成交价（元）</th>
																<th>每单拍下数量</th>
															</tr>
														</thead>
														<tbody>
															<tr>
																<td>
																	<!-- <div style="float: left;"><img width="100" height="100" src="https://gd1.alicdn.com/imgextra/i5/TB13XNyLFXXXXbsXVXXYXGcGpXX_M2.SS2_400x400.jpg"/></div> -->
																	<div style="float: left;">
																		<img width="100" height="100"
																			src="${pic_root }${productin1.id.mainMap }" />
																	</div>
																</td>
																<td>￥${productin1.id.price }</td>
																<td>${productin1.id.perOrderContainingNum }</td>
															</tr>
															<tr>
																<td colspan="3">链接：<a target="_blank"
																	href="${productin1.id.productLink }">${productin1.id.productLink }</a>
																</td>
															</tr>
														</tbody>
													</table>
												</div>
											</div>
										</c:forEach>
									</div>
								</div>
							</c:if>
						</form>
					</div>
				</div>
			</div>
		</div>

		<div class="panel panel-default bk-bg-white">
			<div class="panel-heading bk-bg-white">
				<h2>增值服务</h2>
			</div>
			<div class="panel-body">
				<div class="form-group col-sm-12">
					<div class="col-sm-12">
						<c:forEach items="${taskAddedservics }" var="taskAddedservic">
							<c:if test="${taskAddedservic.level == 1 }">
								<h3>${taskAddedservic.name }</h3>
							</c:if>
							<c:if test="${taskAddedservic.level == 2 }">
								<h4 style="padding-left: 20px">${taskAddedservic.name }${taskAddedservic.value }</h4>
								<c:if test="${taskAddedservic.key=='22' }">
									<div style="padding-left: 20px; width: 70%">
										<div class="table-responsive">
											<table class="table table-bordered">
												<thead>
													<tr>
														<th width="16%">搜索关键词</th>
														<c:if test="${taskAddedservic.attrs['key221']=='1' }">
															<th width="16%">匹配浏览订单数</th>
														</c:if>
														<c:if test="${taskAddedservic.attrs['key222']=='1'  }">
															<th width="16%">收藏加购物车数</th>
														</c:if>
														<c:if test="${taskAddedservic.attrs['key223']=='1'  }">
															<th width="16%">商品评价</th>
														</c:if>
													</tr>
												</thead>
												<tbody>
													<c:forEach items="${taskAddedservic.attrs['list'] }"
														var="item">
														<tr>
															<td>${item.id.searchKeyword }</td>
															<c:if test="${taskAddedservic.attrs['key221']=='1' }">
																<td>${item.id.browseOrders  }</td>
															</c:if>
															<c:if test="${taskAddedservic.attrs['key222']=='1' }">
																<td>${item.id.collectionAndShoppingCart }</td>
															</c:if>
															<c:if test="${taskAddedservic.attrs['key223']=='1' }">
																<td>${item.id.productReviews }</td>
															</c:if>
														</tr>
													</c:forEach>
												</tbody>
											</table>
										</div>
									</div>
								</c:if>
							</c:if>
							<c:if test="${taskAddedservic.level == 3 }">
								<h5 style="padding-left: 40px">${taskAddedservic.name }${taskAddedservic.value }</h5>
							</c:if>
							<c:if test="${taskAddedservic.level == 4 }">
								<h6 style="padding-left: 60px">${taskAddedservic.name }${taskAddedservic.value }</h6>
							</c:if>
						</c:forEach>
					</div>
				</div>
			</div>
		</div>


		<div class="panel panel-default bk-bg-white">
			<div class="panel-heading bk-bg-white">
				<h2>
					押金金额<small>(此金额为商家发布任务时所计算金额，最终任务完成后实际金额会产生多退少补的情况，具体变动请参考资金明细)</small>
				</h2>
			</div>
			<div class="panel-body">
				<div class="form-group col-sm-12">
					<div class="col-sm-12">
						<div class="table-responsive">
							<h3>任务基础金额</h3>
							<table class="table table-bordered">
								<thead>
									<tr>
										<th width="16%"></th>
										<th width="16%">单价</th>
										<th width="16%">件/单</th>
										<th width="16%">邮费</th>
										<th width="16%">单数</th>
										<th width="16%">总基础金额</th>
									</tr>
								</thead>
								<tbody>
									<c:choose>
										<c:when
											test="${task.taskGroupTypeId.task2typeId!=2 and task.taskGroupTypeId.task2typeId!=7 and task.taskGroupTypeId.task2typeId!=9}">
											<tr>
												<td>主商品</td>
												<td>${productin.id.price  }</td>
												<td>${productin.id.perOrderContainingNum }</td>
												<td rowspan="${productin_not.size()+2 }">${basecommission.postage}</td>
												<td rowspan="${productin_not.size()+2 }">${task.totalOrders }</td>
												<td rowspan="${productin_not.size()+2 }">${taskBasePrice}</td>
											</tr>
											<c:forEach items="${productin_not }" var="pro"
												varStatus="status">
												<tr> 
													<td>附加商品${status.index+1 }</td>
													<td>${pro.id.price  }</td>
													<td>${pro.id.perOrderContainingNum  }</td>
												</tr>
											</c:forEach>
											<tr>
												<td>基础佣金</td>
												<td>${basecommission.buyersCommission  }</td>
												<td>1</td>
											</tr>
										</c:when>
										<c:otherwise>
											<tr>
												<td>基础佣金</td>
												<td>${basecommission.buyersCommission}</td>
												<td>1</td>
												<td>0</td>
												<td>${task.totalOrders }</td>
												<td>${taskBasePrice}</td>
											</tr>
										</c:otherwise>
									</c:choose>
								</tbody>
							</table>
						</div>
						<div class="table-responsive">
							<h3>增值服务佣金</h3>
							<table class="table table-bordered">
								<thead>
									<tr>
										<th width="16%">类别</th>
										<th width="16%">项目</th>
										<th width="16%">单价</th>
										<th width="16%">数量</th>
										<th width="16%">明细金额</th>
										<th width="16%">总增值佣金</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${addServicePrice.get('1') }"
										var="servicePrice" varStatus="status">
										<tr>
											<c:if test="${status.index==0 }">
												<td rowspan="${addServicePrice.get('1').size() }">安全服务</td>
											</c:if>
											<td>${servicePrice.current }</td>
											<td>${servicePrice.price }</td>
											<td>${servicePrice.count }</td>
											<td>${servicePrice.price*servicePrice.count }</td>
											<c:if test="${status.index==0}">
												<td
													rowspan="${addServicePrice.get('1').size()+addServicePrice.get('2').size()+addServicePrice.get('26').size() }">${allPrice }</td>
											</c:if>
										</tr>
									</c:forEach>
									<c:forEach items="${addServicePrice.get('2') }"
										var="servicePrice" varStatus="status">
										<tr>
											<c:if test="${status.index==0 }">
												<td rowspan="${addServicePrice.get('2').size() }">权重优化服务</td>
											</c:if>
											<td>${servicePrice.current }</td>
											<td>${servicePrice.price }</td>
											<td>${servicePrice.count }</td>
											<td>${servicePrice.price*servicePrice.count }</td>
											<c:if
												test="${status.index==0&&empty addServicePrice.get('1')}">
												<td
													rowspan="${addServicePrice.get('1').size()+addServicePrice.get('2').size()+addServicePrice.get('26').size() }">${allPrice }</td>
											</c:if>
										</tr>
									</c:forEach>
									<c:forEach items="${addServicePrice.get('26') }"
										var="servicePrice" varStatus="status">
										<tr>
											<c:if test="${status.index==0 }">
												<td rowspan="${addServicePrice.get('26').size() }">效率服务</td>
											</c:if>
											<td>${servicePrice.current }</td>
											<td>${servicePrice.price }</td>
											<td>${servicePrice.count }</td>
											<td>${servicePrice.price*servicePrice.count }</td>
											<c:if
												test="${status.index==0&&empty addServicePrice.get('1')&&empty addServicePrice.get('2')}">
												<td
													rowspan="${addServicePrice.get('1').size()+addServicePrice.get('2').size()+addServicePrice.get('26').size() }">${allPrice }</td>
											</c:if>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
						<div class="text-right" style="padding-right: 50px">
							<h3>
								总计：
								<ins>&nbsp;&nbsp;${totalPrice }&nbsp;&nbsp;</ins>
								元
							</h3>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="form-group " style="text-align: center;">
			<button type="button" id="back" class="btn btn-warning btn-sm"
				style="width: 150px">返回</button>
		</div>
	</div>
	<script type="text/javascript">
		$(function($) {
			//取消
			$('#back').click(function() {
				window.location.href = path + "/task/index";
			});
			$('#orderlist').click(
					function() {
						window.location.href = path
								+ "/order/index?taskid=${task.taskId}";
					});
			$('#cancelOrder').click(function() {
				$.blockUI({
					message : '加载中...'
				});
				$.ajax({
					type : "post",
					url : path + "/task/cancelOrder",
					cache : false,
					data : {
						taskId : '${task.taskId }',
						_t : new Date().getTime()
					},
					dataType : "json",
					success : function(data) {
						if (data.success) {
							showmessage(data.msg, function() {
								location.reload();
							});
						} else {
							$.unblockUI();
							showmessage(data.msg);
						}
					}
				});
			});
		});
		//显示消息
		function showmessage(msg, callback) {
			$('#message').ucMessage({
				msg : msg,
				callback : callback
			});
		}
	</script>
</body>
</html>